<?php
class baseentity
{
    protected $id;
    //protected $ver;
    private $isinsert = false;
    private $isupdate = false;
    private $isdelete = false;
    private $relations = array();

    public function __construct($args=array())
    {
        if(false == isset($args['entity_onload']))
        {
            $this->id = matrix::get('idmakersvc')->createid();
            entityrepo::put($this);
            $this->isinsert = true;
        }
    }

    public function addrelation(relation $relation)
    {
        $this->relations[$relation->_ref] = $relation; 
    }

    public function getrelation()
    {
        return $this->relations;
    }

    public function setallfalse()
    {
        $this->isinsert = false;
        $this->isupdate = false;
        $this->isdelete = false;
    }

    public function __set($property, $value)
    {
        //这里千万不要掉用 可以让 __get方法起作用的 东西。！！！ 切记
         $this->$property = $value;
         $this->isupdate = true;
    }

    public function __get($property)
    {
        $relations = $this->getrelation(); 
        if(isset($relations[$property]))
        {
            return $relations[$property]->loadrelatedentities();
        }
        return $this->$property;
    }

    public function remove()
    {
        $this->isdelete = true;
    }

}
